package io.renren.modules.generator.service.impl;

import io.renren.modules.generator.entity.GongxuDto;
import io.renren.modules.generator.entity.OrderDto;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.JitaiDao;
import io.renren.modules.generator.entity.JitaiEntity;
import io.renren.modules.generator.service.JitaiService;


@Service("jitaiService")
public class JitaiServiceImpl extends ServiceImpl<JitaiDao, JitaiEntity> implements JitaiService {
    @Autowired
    private JitaiDao jitaiDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<JitaiEntity> page = this.page(
                new Query<JitaiEntity>().getPage(params),
                new QueryWrapper<JitaiEntity>()
                .like(StringUtils.isNotBlank(key),"no",key)
        );

        return new PageUtils(page);
    }

    @Override
    public List<OrderDto> test(Map<String, Object> params) {
        String code = (String) params.get("code");
        String chejian = (String) params.get("chejian");
        return jitaiDao.test(code,chejian);
    }

    @Override
    public List<GongxuDto> gongxu(Map<String, Object> params) {
        String nameb = (String) params.get("key");
        return jitaiDao.gongxu(nameb);
    }

    @Override
    public void updateSort(Integer id, Integer sort) {
        jitaiDao.updateSort(id,sort);
    }

    @Override
    public void kaigong(Integer id, String kaigong, Date startDate,Date  finishDate) {
        if (kaigong.equals("已开工")){
            startDate=new Date();
            jitaiDao.kaigong(id,kaigong,startDate,null);
        }else {
            finishDate=new Date();
            jitaiDao.kaigong(id,kaigong,null,finishDate);
        }

    }

}